<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!--    引入semantic.min.css-->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
  <!--    引入me.css-->
  <link rel="stylesheet" href="../../static/css/me.css">
  <title>消息管理</title>
</head>
<body>

<!--导航-->
<nav th:replace="admin/_fragments :: menu(5)" class="ui inverted attached segment m-padded-tb-mini">
  <div class="ui container"> <!-- 加一个容器 -->
    <div class="ui inverted secondary stackable menu"> <!-- 菜单 stackable:可堆叠的,表示屏幕小时自动堆叠-->
      <h2 class="ui white header item">GuideSystem</h2> <!-- 蓝绿色标题 --> <a href="#"
                                                                               class="active m-item m-mobile-hide item"><i
          class="home icon"></i>博客</a> <!-- icon表示图表 -->
      <a href="#" class="m-item m-mobile-hide item"><i class="idea icon"></i>分类</a>
      <a href="#" class="m-item m-mobile-hide item"><i class="tags icon"></i>标签</a>
      <div class="right m-item m-mobile-hide menu">
        <div class="ui dropdown item">
          <div class="text">
            <img class="ui avatar image" src="https://unsplash.it/100/100?image=1005">
            软件214项目组
          </div>
          <i class="dropdown icon"></i>
          <div class="menu">
            <a href="#" class="item">注销</a>
          </div>
        </div>
      </div>
    </div>
  </div>
  <a href="#" class="ui menu toggle black button icon m-top-right m-mobile-show">
    <i class="sidebar icon"></i>
  </a>
</nav>

<!--中间内容-->
<div class="m-container m-padded-tb-big" style="padding-top: 4em !important;" id="contentDiv">
  <div class="ui container">

    <!--        表格-->
    <div id="table-container" style="margin-top: 5em;">
      <table class="ui celled striped table">
        <thead>
        <tr>
          <th colspan="4">
            消息列表
          </th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="news,iterStat : ${pageNews.list}">
          <td class="collapsing">
            <i class="folder open icon" th:classappend="${iterStat.index % 2 == 1 ? 'outline' : ''}"></i>
            <span th:text="${#strings.length(news?.title) > 12 ? news?.title.substring(0, 12) + '...' : news?.title}">node_modules</span>
          </td>
          <td th:text="${#strings.length(news?.content) > 40 ? news?.content.substring(0, 40) + '...' : news?.content}">
            Initial commit
          </td>
          <td class="right aligned collapsing" th:text="${#dates.format(news.createTime, 'yyyy-MM-dd')}">
            10 hours ago
          </td>
          <td class="collapsing">
            <a th:data-url="@{/admin/news/delete/{id}(id=${news?.id})}" onclick="deleteNews(this)"
               class="ui mini gray basic button">删除</a>
          </td>
        </tr>
        <!--/*-->
        <tr>
          <td class="collapsing">
            <i class="file outline icon"></i> <span>package.json</span>
          </td>
          <td>Initial commit</td>
          <td class="right aligned collapsing">10 hours ago</td>
          <td class="collapsing">
            <a th:href="@{/admin/resources/{id}/delete(id=${resource.id})}"
               class="ui mini gray basic button">删除</a>
          </td>
        </tr>
        <!--*/-->
        </tbody>
        <!--            表尾-->
        <tfoot>
        <tr th:if="${pageNews.total}>6">
          <th colspan="7">
            <div class="ui pagination menu">
              <!--th:unless="${page.first}"表示如果不是第一页，这个item才会显示-->
              <a th:href="@{/admin/news(pageNum=${pageNews.hasPreviousPage}?${pageNews.prePage}:1)}" class="item"
                 th:unless="${pageNews.isFirstPage}">上一页</a>
              <a th:href="@{/admin/news(pageNum=${pageNews.hasNextPage}?${pageNews.nextPage}:${pageNews.pages})}"
                 class="item"
                 th:unless="${pageNews.isLastPage}">下一页</a>
            </div>
          </th>
        </tr>
        </tfoot>
      </table>
      <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
        <i class="close icon"></i>
        <div class="header">提示：</div>
        <p th:text="${message}">操作成功。</p>
      </div>
    </div>
  </div>
</div>

<!--底部footer-->
<footer th:replace="admin/_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">
  <!-- vertical:垂直的 segment:条横 inverted:倒置的 -->
  <div class="ui center aligned container"> <!-- center aligned:居中 aligned:使成为一条线-->
    <div class="ui inverted divided stackable grid"> <!-- inverted divided grid:格线分成16份 -->
      <div class="three wide column">
        <div class="ui inverted link list">
          <div class="item">
            <img src="../../static/images/WeChat.jpg" class="ui rounded image" alt="" style="width: 110px">
            <!-- rounded:圆角 -->
          </div>
        </div>
      </div>

      <!-- 分成三列 -->
      <div class="three wide column">
        <h4 class="ui inverted header m-text-thin">最新博客</h4>
        <div class="ui inverted link list">
          <a href="#" class="item m-text-thin">用户故事(User Story)</a>
          <a href="#" class="item m-text-thin">关于小熊是我对象这件事</a>
          <a href="#" class="item m-text-thin">摇滚乐牛逼!</a>
        </div>
      </div>

      <!-- 分成三列 -->
      <div class="three wide column">
        <h4 class="ui inverted header m-text-thin">联系我</h4>
        <div class="ui inverted link list">
          <a href="#" class="item m-text-thin" style="height: 28px">QQ: 1923326384</a>
          <a href="#" class="item m-text-thin">邮箱: 1923326384@qq.com</a>
        </div>
      </div>

      <!-- 分成七列 -->
      <div class="seven wide column">
        <h4 class="ui inverted header m-text-thin">个人留言</h4>
        <p class="m-text-thin m-text-spaced m-opacity-mini m-text-lined">
          第一次跟着视频敲项目，尽管很多不知道的知识点但还是慢慢吞吞地敲下来了，后续肯定会自己独立完成一些项目，希望可以鼓励到自己。</p>
      </div>

    </div>
    <div class="ui inverted section divider"></div>
    <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright @ 2021-2022 Hanyufan Designed by Hanyufan</p>
  </div>
</footer>

<th:block th:replace="admin/_fragments :: script">
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
</th:block>

<!--点击执行操作-->
<script>

    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    $('.message .close').on('click', function () {
        $(this).closest('.message').transition('fade');
    });

    async function deleteNews(button) {
        const url = button.dataset.url;

        await fetch(url, {
            method: 'POST',
            credentials: 'same-origin', // 或者其他适合你的请求认证方式
        }).then(response => {
            if (!response.ok) {
                throw new Error('Failed to delete forum');
            }
            location.reload(); // 刷新页面
        });
    }

</script>
</body>
</html>